<template>
  <div>
    <a-modal
      title="新增网点"
      :visible.sync="commissionVisible"
      custom-class="ad-dialog"
      width="40%"
      @cancel="commissionVisible = false"
      @ok="handleOk"
    >
      <el-form size="small" inline ref="addformRef" :model="siteAdmin" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="网点名称：" prop="name" :rules="[{ required: true, message: '请输入网点名称' }]">
              <el-input v-model="siteAdmin.name" placeholder="请输入" style="width: 195px" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="地址：" prop="address" :rules="[{ required: true, message: '请输入地址' }]">
              <el-input v-model="siteAdmin.address" placeholder="请输入" style="width: 195px" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所在城市：" prop="regionCode" :rules="[{ required: true, message: '请选择所在城市' }]">
              <ad-city-select v-model="siteAdmin.regionCode" :cityData="cityData" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="服务城市："
              prop="chargeCodeList"
              :rules="[{ required: true, message: '请选择服务城市' }]"
            >
              <ad-city-multi-select v-model="siteAdmin.chargeCodeList" :cityData="cityData" />
            </el-form-item>
          </el-col>
          <!--          <el-col :span="12">-->
          <!--            <el-form-item label="选择角色：" prop="roleId">-->
          <!--              <roleSel :modelValue.sync="siteAdmin.roleId" />-->
          <!--            </el-form-item>-->
          <!--          </el-col>-->
        </el-row>
      </el-form>
    </a-modal>
  </div>
</template>
<script>
import AdCitySelect from '@/components/AdCitySelect/index.vue'
import AdCityMultiSelect from '@/components/AdCityMultiSelect/index.vue'
import { getLevelList } from '@/api/city/provinceCity'
import { getRolePage } from '@/api/modular/system/roleManage'
import roleSel from '@/components/roleSel/index.vue'
import { sysOrgAdd, userOrgAdd } from '@/api/modular/system/orgManage'
export default {
  name: 'addNetwork',
  components: { AdCityMultiSelect, AdCitySelect, roleSel },
  data() {
    return {
      commissionVisible: false,
      cityData: [],
      roleOptions: [],
      siteAdmin: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 15 }
      }
    }
  },
  created() {
    getLevelList().then(res => (this.cityData = res.data))
  },
  methods: {
    async handleOk() {
      this.$refs.addformRef.validate(valid => {
        if (valid) {
          userOrgAdd({ ...this.siteAdmin })
            .then(res => {
              if (res.success) {
                this.$message.success('新增成功')
                this.$emit('success')
              } else {
                this.$message.error('新增失败：' + res.message)
              }
            })
            .finally(() => {
              this.commissionVisible = false
            })
        }
      })
    }
  }
}
</script>

<style scoped lang="scss"></style>
